from bumblebee.lib.base import *
from bumblebee.lib.auth import signin, signout

class LoginController(BaseController):

    def index(self):
        return render('/login.mako')

    def signin(self):
        username = request.params.get('username')
        password = request.params.get('password')
        user = model.User.authenticate(username, password)
        if user:
            signin(user)
            h.flash('Welcome back, %s' % user.username)
            redirect_to(controller='dashboard')
        else:
            h.flash('Invalid username or password')
            redirect_to(action='index')

    def signout(self):
        signout()
        redirect_to(action='index')
 
        